package lab03.Test05;
import java.io.*;
/**
 * Created by 李晓容 on 2017/12/12.
 */
public class Test {
    public static void main(String[] args) {
        String path1 = "E://java.txt";
        String path2 = "E://test(2).txt";
        BufferedWriter writer=null;
        BufferedWriter writer2=null;
        BufferedReader reader=null;
        try {
            writer = new BufferedWriter(new FileWriter(path1));
            writer.write("Hello");
            reader = new BufferedReader(new FileReader(path1));
            writer2 = new BufferedWriter(new FileWriter(path2));
            String line;
            String str=null;
            while ((line=reader.readLine())!=null)
            {
                for(int i=0;i<line.length();i++){
                    char ch=line.charAt(i);
                    if(Character.isLetter(ch)){
                        if(Character.isUpperCase(ch)){    //大写
                            if(ch-'A'+1>25){
                                ch=(char) (('A'+(ch-'A'+1)%26)+26);
                            }else{
                                ch=(char) (ch+27);
                            }
                        }
                        if(Character.isLowerCase(ch)){    //小写
                            if(ch-'a'+1>25){
                                ch=(char) ('a'+(ch-'a'+1)%26);
                            }else{
                                ch=(char) (ch+1);
                            }
                        }
                    }
                    str=str+ch;
                }
                writer2.write(str);
                writer2.newLine();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();}catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
                writer2.close();
                reader.close();

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("文件加密完毕！");
    }
}
